package com.api.shopapi.mapper;

import com.api.shopapi.entity.OrderRefundApply;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderRefundApplyMapper {

    @Insert("insert into order_refund_apply (OrderRefundApplyCode,OrderBusinessCode,RefundType,CreateTime,Remarks,ImgUrl,ReturnMoney) " +
            "values (#{orderRefundApply.OrderRefundApplyCode},#{orderRefundApply.OrderBusinessCode},#{orderRefundApply.RefundType}," +
            "#{orderRefundApply.CreateTime},#{orderRefundApply.Remarks},#{orderRefundApply.ImgUrl},#{orderRefundApply.ReturnMoney})")
    int insert(@Param("orderRefundApply") OrderRefundApply orderRefundApply);

    @Update("update order_refund_apply set OrderBusinessCode=#{orderRefundApply.OrderBusinessCode},RefundType=#{orderRefundApply.RefundType}," +
            "Remarks=#{orderRefundApply.Remarks},ImgUrl=#{orderRefundApply.ImgUrl},ReturnMoney=#{orderRefundApply.ReturnMoney} where " +
            "OrderRefundApplyCode=#{orderRefundApply.OrderRefundApplyCode}")
    int update(@Param("orderRefundApply") OrderRefundApply orderRefundApply);

    @Delete("delete from order_refund_apply where OrderRefundApplyCode=#{orderRefundApplyCode}")
    int delete(@Param("orderRefundApplyCode") String orderRefundApplyCode);

    @Select("select * from order_refund_apply where OrderRefundApplyCode=#{orderRefundApplyCode} limit 1")
    OrderRefundApply getByOrderRefundApplyCode(@Param("orderRefundApplyCode") String orderRefundApplyCode);

    @Select("<script>" +
            "select * from order_refund_apply ora LEFT JOIN order_business ob on ora.OrderBusinessCode=ob.OrderBusinessCode " +
            "left join `order` o on o.OrderCode=ob.OrderCode where 1=1" +
            " <if test ='userCode !=null and userCode!=\"\"  '>" +
            "  and o.UserCode =#{userCode}  " +
            " </if>" +
            " <if test ='businessCode !=null and businessCode!=\"\"  '>" +
            "  and ob.BusinessCode =#{businessCode}  " +
            " </if>" +
            "</script> ")
    List<OrderRefundApply> getPageList(@Param("userCode") String userCode,@Param("businessCode") String businessCode);
}


